//
//  payVC.m
//  jiaKaoZhuShou
//
//  Created by 金艺社 on 2018/5/25.
//  Copyright © 2018年 金艺社. All rights reserved.
//

#import "payVC.h"
#import <AlipaySDK/AlipaySDK.h>
#define AppScheme  @"ShouNew"
@interface payVC ()

@end

@implementation payVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"支付";
    UIButton *pay = [UIButton new];
    pay.backgroundColor = [UIColor greenColor];
    [pay setTitle:@"支付" forState:0];
    pay.titleLabel.font = [UIFont systemFontOfSize:15];
    [pay addTarget:self action:@selector(playClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:pay];
    [pay mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.centerY.equalTo(self.view);
    }];
    [self.view layoutIfNeeded];
    pay.layer.masksToBounds = YES;
    pay.layer.cornerRadius = pay.frame.size.width / 2;
}
- (void)playClick {
    [[AlipaySDK defaultService] payOrder:[self generateTradeNO] fromScheme:AppScheme callback:^(NSDictionary *resultDic) {
        NSLog(@"reslut = %@",resultDic);
    }];
}

- (NSString *)generateTradeNO
{
    static int kNumber = 15;
    NSString *sourceStr = @"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    NSMutableString *resultStr = [[NSMutableString alloc] init];
    srand((unsigned)time(0));
    for (int i = 0; i < kNumber; i++)
    {
        unsigned index = rand() % [sourceStr length];
        NSString *oneStr = [sourceStr substringWithRange:NSMakeRange(index, 1)];
        [resultStr appendString:oneStr];
    }
    return resultStr;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
